/*
*
** 流程表单绑定数据(根据系统字典-流程表单绑定数据)
* ykf
* 仅支持 select
**
* 1 -   驾驶员数据
* 2 -   出车车辆数据
* */

UserInfo.init();

function renderBindingData() {
    $("[binding-data]").each(function () {
        currentElement = $(this)
        var dataValue = currentElement.attr("binding-data")
        if (dataValue == "" || dataValue == null) return true

        //把需要绑定的数据项转换为字典， 如 dictOption
        var dictOption = {
            "option-value1": "option-text1",
            "option-value2": "option-text2"
        }

        switch (dataValue) {
            case "1":   //demo
                ActHttpRequest("",{ }, function (data) {
                    if(data.OK != "OK"){
                        layer.alert(data.message);
                        return;
                    }
                    // console.log(data)

                    //转为字典
                    dictOption = {}
                    for(var i=0; i<data.List.length; i++) {
                        dictOption[data.List[i].userId] = data.List[i].userName
                    }

                    //渲染表单
                    renderSelectData(currentElement, dictOption)
                });

                break;
        }
    })

}

function renderSelectData(iElement, dictOption) {
    var selectedMask = ""

    iElement.html("")
    iElement.append("<option value=\"\"></option>")

    for (var ikey in dictOption) {
        if (ikey == iElement.attr("value-code")) {
            selectedMask = "selected"
        } else {
            selectedMask = ""
        }

        iElement.append("<option value='" + ikey + ":" + dictOption[ikey] + "' " + selectedMask + ">" + dictOption[ikey] + "</option>")
    }
}

function selectArea(e) {
    console.log(123)
    parent.layer.open({
        type: 2
        , title: '选择人员'
        , area: ['900px', '700px']
        , maxmin: false
        , content: 'atrr.html?sessionStrogeName=erp_yy_selectArea'
        , zIndex: layer.zIndex
    });
}